﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Reflection;
using System.IO;
using System.Diagnostics;

namespace Unleashed.AutoUpdate.IO.Configuration
{
    /// <summary>
    /// Main configuration of the client application (configuration file is distributed with the client application)
    /// </summary>
    [Serializable]
    [XmlRoot("updateConfiguration")]
    internal class UpdateConfig
    {
        private UpdateConfig() { }

        [XmlIgnore]
        public string ConfigurationPath { get; set; }

        public static UpdateConfig Load(string path)
        {
            UpdateConfig res = new UpdateConfig();
            res.ConfigurationPath = path;

            Debug.WriteLine("Loading new config from: " + path);
            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                XmlSerializer xml = new XmlSerializer(typeof(UpdateConfig));
                res = (UpdateConfig)xml.Deserialize(fs);
                fs.Close();
            }

            return res;
        }

        [XmlAttribute("customActionsTypeName")]
        public string CustomActionTypeName { get; set; }

        [XmlAttribute("customActionAssemblyName")]
        public string CustomActionAssemblyName { get; set; }

        [XmlElement("dialogs")]
        public List<DialogConfigSection> Dialogs { get; set; }

        [XmlElement("files")]
        public List<FileCompareWorker> Files { get; set; }
    }
}